package com.iwdnb.gkgz.common.enums;

import java.math.BigDecimal;

import com.iwdnb.bmnf.common.enums.CodeMessage;
import com.iwdnb.gkgz.common.utils.BigDecimalUtils;

public enum IntersectTypeEnums implements CodeMessage {
    UP_BIG("upb", "短均线在长周期上方并扩大差距"),
    UP_SMALL("ups", "短均线在长周期上方并缩小差距"),

    DOWN_BIG("downb", "短均线在长周期下方并扩大差距"),
    DOWN_SMALL("downs", "短均线在长周期下方并缩小差距"),

    DOWN_TO_UP("du", "金叉"),
    UP_TO_DOWN("ud", "死叉");

    private String code;
    private String message;

    IntersectTypeEnums(String code, String message) {
        this.code = code;
        this.message = message;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public static IntersectTypeEnums getType(BigDecimal firstPrice, BigDecimal secondPrice,
        BigDecimal thirdPrice, BigDecimal firstLongPrice, BigDecimal secondLongPrice, BigDecimal thirdLongPrice) {
        if (BigDecimalUtils.isGe(firstPrice, firstLongPrice)) {
            if (BigDecimalUtils.isLt(secondPrice, secondLongPrice)
                || BigDecimalUtils.isLt(thirdPrice, thirdLongPrice)) {
                return UP_TO_DOWN;
            } else {
                BigDecimal firstRate = BigDecimalUtils.subStractAndDividePrecent(firstPrice, firstLongPrice);
                BigDecimal thirdRate = BigDecimalUtils.subStractAndDividePrecent(thirdPrice, thirdLongPrice);
                if (BigDecimalUtils.isGt(thirdRate, firstRate)) {
                    return UP_BIG;
                } else {
                    return UP_SMALL;
                }
            }
        } else {
            if (BigDecimalUtils.isGe(secondPrice, secondLongPrice)
                || BigDecimalUtils.isGe(thirdPrice, thirdLongPrice)) {
                return DOWN_TO_UP;
            } else {
                BigDecimal firstRate = BigDecimalUtils.subStractAndDividePrecent(firstLongPrice, firstPrice);
                BigDecimal thirdRate = BigDecimalUtils.subStractAndDividePrecent(thirdLongPrice, thirdPrice);
                if (BigDecimalUtils.isGt(thirdRate, firstRate)) {
                    return DOWN_BIG;
                } else {
                    return DOWN_SMALL;
                }
            }
        }
    }
}
